﻿#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include "childedit.h"
#include "widget_setting.h"
#include "widget_about.h"
#include "widget_find.h"
#include "widget_replace.h"
#include <QMdiSubWindow>
#include <QSettings>
#include "global_define.h"
#include "serial_func.h"
#include "order_handle.h"
#include <QTimer>
#include <QQueue>
#include <QProgressBar>
#include <QPushButton>
#include "order_handle/json_handle.h"
#include "order_handle/json_explain.h"
#include "loopque.h"
#include "oasnapshotinterface.h"
#define singleFile 1

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

protected:
    void closeEvent(QCloseEvent *event);
private slots:
    void updateMenus();
    void on_actionNew_triggered();

    void on_actionOpen_triggered();

    void on_actionSave_triggered();

    void on_actionSaveAs_triggered();

    void on_actionExit_triggered();

    void on_actionCopy_triggered();

    void on_actionCut_triggered();

    void on_actionPaste_triggered();

    void on_actionUndo_triggered();

    void on_actionRedo_triggered();

    void on_actionClose_triggered();

    void on_actionCloseAll_triggered();

    void on_actionTile_triggered();

    void on_actionCascade_triggered();

    void on_actionNext_triggered();

    void on_actionPrevious_triggered();

    void on_actionDownload_triggered();

    void on_action_Option_triggered();

    void on_actionAbout_triggered();

    void on_action_Run_triggered();

    void on_action_Find_triggered();

    void on_action_Replace_triggered();

    void on_action_Simulate_triggered();

    void on_action_goto_triggered();

    void on_action_help_triggered();

public slots:
    void saveLastCloseFilePath_slot(QString path); //保存上次打开文件的路径
    void uartgetdata_slot(int);                    //数据接收槽
    void uartsentdata_slot();                      //数据发送槽
    void checkQueueData_slot();                    //发送队列数据检查槽
    void showFindText_SLOT(QString exp, QTextDocument::FindFlags opt); //查找功能槽
    void showReplaceText_SLOT(QString exp, QString after,
                              QTextDocument::FindFlags opt,int func);  //替换功能槽
    void reload_setting_slot();                    //重载设置槽
    void FileOpen_slot(QString url);               //打开文档槽
    void transfers_stop_slot(int value);           //传送终止处理槽
    void transfers_stop_slot();                    //传送终止处理槽
signals:
    void sig_readytosent();                        //发送准备完毕信号
    void sig_processChange(int);                   //进度改变信号
    void sig_transfers_stop(int);                  //传输终止信号
    void sig_gotoLine(int);                        //转到行信号
    void sig_savelastfile(QStringList);            //最近打开列表保存完毕信号
private:
    Ui::MainWindow *ui;

    serial_func userUart;           //串口控制器
    order_handle ordermaker;        //数据处理器
    QQueue<QByteArray> senddata;    //待发送队列
    QByteArray sendbuf;             //记录本次发送数据(重发)
    QTimer sendtimer;               //收发定时器
    bool fileTranferFlag;           //当前串口发送为文件传输标志,用于弹出提示
    enum ErrorFlag{
        COMPLETE = 0,
        OVERTIME = -1,
        ABORT    = -2,
        UNLINK   = -3
    };                              //下位机返回错误类型
    QProgressBar *downloadPb;       //下载进度条
    QPushButton *cancelButton;      //取消下载按钮

    QSettings *setting_config;      //配置处理器
    //窗口类
    widget_setting *widget_s;       //设置窗口
    widget_about *widget_ab;        //关于窗口
    widget_find *widget_f;          //查找窗口
    widget_replace *widget_r;       //替换窗口

    QTimer updateWindowsTimer;      //窗口更新定时器
    QAction *actionSeparator;       //分隔符;
    QMdiSubWindow *findMdiChild(const QString &fileName);
    ChildEdit *createMdiChild();    //创建子窗口
    ChildEdit *activeMdiChild();    //查看活动窗口

    void writeSettings();           //写入窗口设置
    void readSettings();            //读取窗口设置
    void initWindow();              //初始化窗口

    //k3
    Json_handle json_handle;
    Json_explain json_explain;

};

#endif // MAINWINDOW_H
